'use strict';

const { Controller } = require('egg');

class HomeController extends Controller {
  async showInfo () {
    var isExamine = 1, isSolve = 1;
    const { ctx } = this;
    try {
      const examineData1 = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from needDrug where isEamine='${isExamine}'`)));
      const examineData2 = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from provideDrug where isEamine='${isExamine}'`)));
      const solveData1 = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from needDrug where isSolve='${isSolve}'`)));
      const solveData2 = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from provideDrug where isSolve='${isSolve}'`)));
      const allData1 = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from needDrug`)));
      const allData2 = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from provideDrug`)));
      const phoneUser = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from user`))).length;
      const examineAll = examineData1.length + examineData2.length;
      const solveAll = solveData1.length + solveData2.length;
      const allData = allData1.length + allData2.length;
      const res = {
        examineAll,
        solveAll,
        allData,
        phoneUser
      };
      ctx.body = {
        code: 200,
        mag: 'success',
        data: res
      };
    } catch (error) {
      ctx.body = {
        code: 500,
        msg: 'fail',
        data: null
      };
    }
    ctx.body;
  }
  async showCoronavirus () {
    const { ctx } = this;
    try {
      const res = JSON.parse(JSON.stringify(await ctx.app.mysql.query(`select * from coronavirus`)));
      ctx.body = {
        code: 200,
        mag: 'success',
        data: res
      };
    } catch (error) {
      ctx.body = {
        code: 500,
        msg: 'fail',
        data: null
      };
    }
  }
}

module.exports = HomeController;
